package com.wzd.testimage;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.telephony.CellInfo;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import com.wzd.testimage.tools.NetUtil;

import java.util.List;


public class MainActivity extends Activity implements ViewSwitcher.ViewFactory {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.activity_main);
       Log.i("wzd", NetUtil.getLocalWifiIp(this));
        /*final ImageSwitcher is = (ImageSwitcher) findViewById(R.id.image_switcher);
        is.setInAnimation(new ScaleAnimation(0.5f, 1f, 0.5f, 1f));
        is.setOutAnimation(new AlphaAnimation(1f, 0));
        is.setFactory(this);
        Gallery gallery = (Gallery) findViewById(R.id.gallery);
        gallery.setAdapter(new ImageAdapter(this));
        gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                is.setImageResource(images[position]);
            }
        });*/
        TextView tv = (TextView) findViewById(R.id.tv);
        tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tv.setText(Html.fromHtml("<span style=\"text-decoration:line-through;\">删除线效果</span><font color=red>呵呵</font>"));
        Log.i("wzd", Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID));
        PackageManager pm = getPackageManager();
        List<ApplicationInfo> infos = pm.getInstalledApplications(0);
        List<PackageInfo> infos1=pm.getInstalledPackages(0);
        for (PackageInfo info1:infos1){
//            Log.i("wzd", info1.toString());
        }
        for (ApplicationInfo info : infos) {

//            Log.i("wzd", info.publicSourceDir+"//////"+info.toString());
        }
    }

    public int[] images = {R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d};

    @Override
    public View makeView() {
        return new ImageView(this);
    }

    class ImageAdapter extends BaseAdapter {

        private Context mContext;

        ImageAdapter(Context context) {
            mContext = context;
        }

        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView iv = new ImageView(mContext);
            iv.setImageResource(images[position]);
            return iv;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private Bitmap bitmap1;
    private Bitmap bitmap2;

    private void imageTest() {
        /*InputStream in1 = getResources().openRawResource(R.raw.test1);
        bitmap1 = BitmapFactory.decodeStream(in1);
        InputStream in2 = getResources().openRawResource(R.raw.test2);
        bitmap2 = BitmapFactory.decodeStream(in2);*/
//        ShaderView imageView = (ShaderView) findViewById(R.id.my_image);
//        imageView.setText("通过一个异步线程来控制歌词渲染的速度");
//        imageView.setImageBitmap(bitmap1);
//        imageView.setBackgroundResource(R.mipmap.ic_launcher);
    }

    private void getTelphoneInfo() {
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
            List<CellInfo> lists = telephonyManager.getAllCellInfo();
            for (CellInfo info : lists) {
                Log.i("wzd", info.toString());
            }
        }
        Log.i("wzd", telephonyManager.getLine1Number());
        Log.i("wzd", telephonyManager.getDeviceId());
        Log.i("wzd", telephonyManager.getDeviceSoftwareVersion());
        Log.i("wzd", telephonyManager.getNetworkCountryIso());
        Log.i("wzd", telephonyManager.getNetworkOperatorName());
        Log.i("wzd", telephonyManager.getSimSerialNumber());
    }
}
